# frozen_string_literal: true

module ExtensionByZhouXi
  # 插件核心功能模块
  module Edgez2
    module_function

    ID = 'Edgez'
    MD = Sketchup.active_model
    DIR = File.dirname(__FILE__)

    def paint_edges_selected(entities, mat)
      entities.each do |x|
        if x.is_a?(Sketchup::Group) || x.is_a?(Sketchup::ComponentInstance)
          paint_edges_selected(x.definition.entities, mat)
        elsif x.is_a?(Sketchup::Edge)
          x.material = mat
        end
      end
    end

    def paint_edge
      paint_edges_selected(MD.selection, MD.materials.current)
      MD.rendering_options['EdgeColorMode'] = 0
      MD.selection.clear
    end

    unless @ui_loaded
      @ui_loaded = true
      cmd = UI::Command.new('paint edge') { paint_edge }
      cmd.small_icon = cmd.large_icon = "#{DIR}/icon.svg"
      cmd.status_bar_text = ('先选中材质，再选中模型，点击工具栏图标一键为边线上色')
      cmd.tooltip = ID
      bar = UI::Toolbar.new(ID)
      bar.add_item cmd
      bar.show
    end
  end
end

# load 'D:/Works/su-edgez/Zhouxi_Edgez_2/core.rb'
